<!doctype html>
<html>
    <head>
        <title>代金券demo</title>
    
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
        <link rel="stylesheet" href="layui.css" media="all">
        <script src="layui.js"></script>
        <script src="jquery.1.12.4.js"></script>
        <link href="lay.css" rel="stylesheet" />
        <style>
        </style>
    </head>
    <body>
        <div id="main">
        </div>
        <script>
            // 获取URL里的参数函数
            function getQueryString(name){
                var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
                var r = window.location.search.substr(1).match(reg);
                if(r!=null)return  unescape(r[2]); return null;
            }
            var code = getQueryString('code');
            $.ajax({
                url: "http://redmany.city1000.cn/red/get/quan",
                type: "post",
                dataType: 'json',
                data: {},
                success: function (data) {
                    console.log(data);
                    for(var i=0; i<data.quan.length; i++){
                        var html = "<div><p><input type='text' disabled value='"+data.quan[i].name+"' /></p><p><input type='text' disabled value='"+data.quan[i].start+"' /></p></diV><div _key='"+data.quan[i].id+"' class='dianjilingqu'>点击领取</div><br>"
                        
                        $("#main").append(html);
                    }

                    var btn = $(".dianjilingqu");
                    btn.click(function(){
                        var ts = $(this);
                        $.ajax({
                            url: "http://redmany.city1000.cn/red/lingqu/post",
                            type: "post",
                            dataType: 'json',
                            data: {
                                "code": code,
                                "qId": ts.attr("_key")
                            },
                            success: function (data) {
                                console.log(data);
                            },
                            error: function (err) {
                                console.log(err)
                            }
                        })
                    })
                    
                },
                error: function (err) {
                    console.log(err)
                }
            })
        </script>
    </body>
</html>